package spec.zhangyuehua.$07;

import java.sql.*;

/**
 * Created by yue on 2017/11/28.
 * 数据库查询测试
 */
public class QueryTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        String urL="jdbc:mysql://Localhost:3306/1613580003";

        String name="root";
        String password="123456";

        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //建立连接
       Connection com=DriverManager.getConnection(urL,name,password);
        //创建查询语句
        Statement s=com.createStatement();
        //添加语句
        s.executeUpdate("insert into t_student values('1','陈一','18')");
        s.executeUpdate("insert into t_student values('2','李二','17')");
        s.executeUpdate("insert into t_student values('3','刘三','18')");
        s.executeUpdate("insert into t_student values('4','罗','16')");
        s.executeUpdate("insert into t_student values('5','陈','22')");
        s.executeUpdate("insert into t_student values('6','许','23')");
        //删除语句
        s.executeUpdate("delete from t_student where (id<3) ");
        //修改语句
        s.executeUpdate("update t_student set name='陈洪' where id='5'");
        s.executeUpdate("update t_student set name='徐红' where id='6'");
        //执行查询
        ResultSet rs=s.executeQuery("select * from t_student");
        //遍历整个表格
        while (rs.next()){
            System.out.println("姓名:"+"  "+rs.getString("name"));
        }
    }
}
